<template>
    <div class="acceptance-registration-pages">
        <commpVxeTable
         :config="dataTableConfig" 
         :columns="columnsVxe" 
         :formItem="formItem"
         @checkboxChange="checkboxChange"
         ref="acceptanceRegistrationRef"
         >
            <template v-slot:externalOperations="{data}"  >
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="addition()">新增</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="batchDeletion()">批量删除</a-button>
                    </template>
                </vxe-form-item>
            </template>
            <template v-slot:jobStatus_slo="{row}" data-desc="自定操作栏">
                <span>{{ row.jobStatus == 1?'正常':(row.jobStatus == 0?'暂停':'') }}</span>
            </template>
            
            <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline" class="search-form" >
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="reviseClick(row)">编辑</a-button>
                    </a-form-item>
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="launchTask(row)">创建任务</a-button>
                    </a-form-item>
                    <a-form-item >
                        <a-button class="red-btn" type="primary" @click="batchDeletion(row)">删除</a-button>
                    </a-form-item>
                </a-form>
            </template>
        </commpVxeTable>
        <increase ref="increaseRef" @handleOk="handleOk"/>
        <a-modal
         :visible="firingVisibleShow" 
         title="添加此模板任务" 
         @ok="firingHandleOk" 
         :forceRender="true"
         @cancel="firingVisibleShow = false">
            <a-form >
                <a-form-item label="任务状态">
                    <compSelector
                        v-model="firingData.autoStopFlag" 
                        compType="Radio"
                        :defaultValue="firingData.autoStopFlag"
                        :options="[{label:'执行一次',value:'1'},{label:'持续执行',value:'0'}]"
                    />
                </a-form-item>
            </a-form>
         </a-modal>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import assessCheckApi from './service/api.js'
import increase from './increase.vue'
import { deleteArrServe, ocalityPostAction, selectScheduleJob } from './service/index'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import moment from 'moment'
import blobType from '@/common/blobType'
import compSelector from '@/components/compSelector/compSelector'
  export default {
    components:{
        commpVxeTable,
        increase,
        compSelector
    },
    
    data(){
        return{
            firingData:{
                id:'',
                autoStopFlag:'1',
            },
            firingVisibleShow:false,
            addEditParameter:{},
            formItem:[
                {
                    label: '模版名称',
                    model: 'mbName',
                },{
                    label: 'bean名称',
                    model: 'beanName',
                },{
                    label: '方法名称',
                    model: 'methodName',
                }

            ],
            columnsVxe:[{ type: 'checkbox', width: 60 ,fixed: 'left',},{
                    title: '模版名称', //列头显示文字
                    field: 'mbName',
                    fixed: 'left',
                },{
                    title: 'bean名称', //列头显示文字
                    field: 'beanName',
                },{
                    title: '方法名称', //列头显示文字
                    field: 'methodName',
                },{
                    title: '方法参数',
                    field: 'methodParams',
                },{
                    title: '状态',
                    field: 'jobStatus',
                    slots: {
                    // 使用插槽模板渲染
                    default: 'jobStatus_slo',
                  },
                },{
                    title: '每隔多少分钟执行',
                    field: 'mgdsfzzx',
                },{
                    title: '操作',
                    field: 'id',
                    slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                  },
                    fixed: 'right',
                    width:300,
                }],
            dataTableConfig:{
                api: assessCheckApi.list,
                rowId: 'id',
                // fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                paramet:{
                }
            },
            specifyDateVal:'',
            isSpecifyDate:false,
            numFigure:1,
            numFigureVisible:false,
            currentReplicationId:'',
            selectedRowKeysArr:[],
        }
    },
    
    methods:{
        timeProcessing(val){
            if(val){
                val = val.slice(0,11)
            }
            return val
        },
        async dictionaryQuery(val){
            let dataObj = []
            await ocalityPostAction({dictName:val}).then(res=>{
                //console.log('字典的res',res)
                if(res.code == 200){
                    if(res.result.length){
                        dataObj = res.result
                    }
                    
                }
            })
            return dataObj
        },
        checkboxChange(val){//获取当前选择的行
            this.selectedRowKeysArr = []
            val.forEach(item => {
                this.selectedRowKeysArr.push(item.id)
            });
        },
        addition(){//新增
            this.$refs.increaseRef.visibleShow = true
            this.$refs.increaseRef.getData({mgdsfzzx:1,jobStatus:'1'})
        },
        //编辑
        reviseClick(val){
            this.$refs.increaseRef.visibleShow = true
            this.$refs.increaseRef.getData({...val,jobStatus:String(val.jobStatus)})
        },
        successReturn(){
            this.$refs.acceptanceRegistrationRef.searchEvent()
        },
        launchTask(row){
            this.firingData.id = row.id
            this.firingVisibleShow = true
        },
        firingHandleOk(){
            var that = this
            this.$confirm({
                title:'您确认添加此模板任务吗？',
                onOk() {
                    selectScheduleJob({id:that.firingData.id,autoStopFlag:that.firingData.autoStopFlag=='1'?true:false}).then(res=>{
                        if(res.code == 200){
                            that.firingVisibleShow = false
                            that.successReturn()
                            that.$message.success(res.message)
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        batchDeletion(row){//
            var that = this
            if(row || that.selectedRowKeysArr.length){
                this.$confirm({
                    title:'您确认要删除吗？',
                    // icon: createVNode(ExclamationCircleOutlined),
                    onOk() {
                        let deleteString = row?row.id:that.selectedRowKeysArr.join(',')
                        deleteArrServe({id:deleteString}).then(res=>{
                            if(res.code == 200){
                                that.$message.success('删除成功')
                            }else{
                                that.$message.warning(res.message)
                            }              
                            that.$refs.acceptanceRegistrationRef.searchEvent()
                        })
                        
                    },
                    
                });
            }else{
                    that.$message.warning('请选择删除项')
            }
            
            
        },
        handleOk(val,id){
            if(val && !id){
                this.$refs.acceptanceRegistrationRef.resetEvent()
            }else if(val && id){
                this.requestParams = {
                    ...this.requestParams,
                    renovate:true,
                }
            }
            
        },
        
        
        AddHandleOk(){
            this.$refs.acceptanceRegistrationRef.resetEvent()
        },
    },

  }
</script>
<style lang="less">
.acceptance-registration-pages{
    .select-date-box{
        display: flex;
        flex-direction: column;
        span{
            color: #f5222d;
            font-size: 14px;
        }
    }
    .modal-btn-box{
        .ant-form-item-control{
            width: 175px !important;
        }
    }
    
}
</style>
<style scoped >
.observer-lbrary-pages{
    background: #fff;
}
.btn-box{
    display: flex;
    justify-content: flex-end;
}
.blue-btn{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
}
.red-btn{
    border: 1px solid #ed5565 !important;
    background-color: #ed5565 !important;
}




</style>